{% extends "layout.html" %}
{% block title %}首页信息管理{% endblock %}
{% block extra_head %}
<script type="text/javascript">
 $(function() {
    /* For zebra striping */
    $("table tr:nth-child(odd)").addClass("odd-row");
    /* For cell text alignment */
    //$("table td:first-child, table th:first-child").addClass("first");
    /* For removing the last border */
    //$("table td:last-child, table th:last-child").addClass("last");

    /**
     * 页面选择处理
     */
    $("#select_page").change(function(){
        var page = $("#select_page").val();
        location.href = "{{ url_for('admin.show_pm_essay') }}?page=" + page;
    });

    /**
     * 控制页码导航栏显示的页码数
     */
    var lie_page_num = 14  // 定义每页最多显示的页码数
    var cur_page = Number({{ cur_page }});
    var total_page = Number({{ total }});

    if (cur_page <= lie_page_num && total_page > lie_page_num)
    {
        var hide_a_start = lie_page_num + 1;
        var hide_a_end = total_page;

        for (var i = hide_a_start; i <= hide_a_end; i++)
        {
            var hid_a_id = "#" + String(i);
            $(hid_a_id).css("display", "none");
        }
    }
    else if (cur_page > (total_page - lie_page_num))
    {
        for (var i = 1; i <= total_page - lie_page_num; i++)
        {
            var hid_a_id = "#" + String(i);
            $(hid_a_id).css("display", "none");
        }
    }
    else if (total_page > (lie_page_num * 2))
    {
        if (cur_page % lie_page_num == 0)
        {
            var base_page = Math.floor((cur_page - 1) / lie_page_num) * lie_page_num;
        }
        else
        {
            var base_page = Math.floor(cur_page / lie_page_num) * lie_page_num;
        }

        for (var i = 1; i <= base_page; i++)
        {
            var hid_a_id = "#" + String(i);
            $(hid_a_id).css("display", "none");
        }

        for (var i = base_page + lie_page_num + 1; i <= total_page; i++)
        {
            var hid_a_id = "#" + String(i);
            $(hid_a_id).css("display", "none");
        }
    }
    else
    {
        console.log("Unknown error");
    }

});
</script>
{% endblock %}
{% block content %}
<table cellspacing="0">
<caption>页面管理 / 网址导航</caption>
<tr><th>编号</th><th>发布时间</th><th>发布内容</th></tr>
{% for serial, essay in essays %}
<tr>
    <td>&nbsp;&nbsp;&nbsp;{{ serial + 1 }}&nbsp;&nbsp;&nbsp;</td>
    <td class="first">{{ essay.date }}</td>
    <td class="first">{{ essay.content }}s</td>
</tr>
{% endfor %}
{% if not total %}
<tr><td colspan=3>没有结果！</td><tr>
{% endif %}
</table>
<div class="pagination">
    <div class="first_page">
        <a href="{{ url_for('admin.show_pm_essay') }}?page=1">首页</a>
    </div>
    {% if pagination.has_prev %}
    <div class="pre_page">
        <a href="{{ url_for('admin.show_pm_essay') }}?page={{ pagination.prev_num }}">上一页</a>
    </div>
    {% endif %}
    <div class="page_num">
        {% for i in range(total) %}
            {% if cur_page == (i + 1) %}
                <span class="current">{{ cur_page }}</span>
            {% else %}
                <a href="{{ url_for('admin.show_pm_essay') }}?page={{ i + 1 }}">{{  i + 1 }}</a>
            {% endif %}
        {% endfor %}
    </div>
    {% if pagination.has_next %}
    <div class="next_page">
        <a href="{{ url_for('admin.show_pm_essay') }}?page={{ pagination.next_num }}">下一页</a>
    </div>
    {% endif %}
    <div class="last_page">
        <a href="{{ url_for('admin.show_pm_essay') }}?page={{ total }}">尾页</a>
    </div>
    <div class="jump_page">
        跳
        <select id="select_page">
            <option value="{{ cur_page }}">{{ cur_page }}</option>
            {% for i in range(total) %}
            <option value="{{ i + 1 }}">{{ i + 1 }}</option>
            {% endfor %}
        </select>
        / {{ total }}页
    </div>
</div>
{% endblock %}
